package 多无人机架次;

import GA_Test.GAData;

import java.util.ArrayList;
import java.util.Random;

public class Compute {
    /**
     * 该方法返回 object[] 类型的数据  里面存放的应该是 两个ArrayList[]<Object> 的数据集  一个是 truckgenes  一个是dronegenes
     * 如果出现未打印出路径：可能存在的bug是  s中有一个j值 每次会调到-1  容易导致循环直接结束
     *   出现类似的逻辑bug 第一个去 看是不是 循环体上的问题
     *   算法目前为  单架次 多访问点
     */
    public static Object[] mainMethod() {
        Object[] obj = new Object[2];
        ArrayList<Object> truck_hub = new ArrayList<>(); //车辆行驶路径集合
        ArrayList<Object> drone_hub = new ArrayList<>();//无人机行驶路径集合
        ArrayList<Integer> w = new ArrayList<Integer>();
        double D = GAData.distanceDrone;//无人机续航距离
        int M = GAData.capacityDrone;//无人机载重
        int Q = GAData.capacityTruck;//车辆载重
        Double sum_time = 0.00;//初始化总运行时间
        //Node[] n_size = ReadDate.ReadNode();
        for (Integer c = 1; c < GAData.cusInfo.length-1; c++) { //初始将所有的顾客节点 加入未访问节点集w
            w.add(c);
        }
        car:
        for (int i = 0; i < 1000; i++) {//车辆选择循环
            //初始化w未访问节点集 f已访问节点集 RT车辆访问节点 RU无人机访问节点  dronetrip是当前车辆的无人机线路集
            ArrayList<Object> hub = new ArrayList<>(100);//hub是一个中转的集合  初始的长度设为100
            for (int j = 0; j < 100; j++) {//这里的j控制了 无人机的架次
                hub.add(new ArrayList<Integer>());
            }
            ArrayList<Object> drone_trip = new ArrayList<Object>(100);
            ArrayList<Integer> f = new ArrayList<Integer>();
            ArrayList<Integer> RT = new ArrayList<Integer>();
            ArrayList<Integer> RU = new ArrayList<Integer>();
            int j;double l = 0.00;ArrayList<Integer> s = null;
           if(w.size()>1) {
               //计算出距离0点最近的两个点   这里改成随机生成第一个点
               Random random = new Random();int ra = random.nextInt(w.size());

               Integer theFirstpoint = w.get(ra);
               w.remove(theFirstpoint);
               //Integer theFirstpoint = Distance.wDistance1(0, w);w.remove(theFirstpoint);
               Integer theSecondPoint = Distance.wDistance1(theFirstpoint, w);
               w.remove(theSecondPoint);

               l = GAData.disCollection[theFirstpoint][theSecondPoint];
               //进行对应距离点的 加入与移除操作
               RU.add(theFirstpoint);
               RT.add(theFirstpoint);
               RT.add(theSecondPoint);
               f.add(theFirstpoint);
               f.add(theSecondPoint);
               if(w.size()==0){
                   PrintRoute.printRoute_w0(RT, RU,w, drone_trip,obj,truck_hub,drone_hub);
                   //sum_time += time;
                   break car;
               }
               s = Distance.sProduce(w, RU);// 获取s
               //如果 s 没有获取成功   并且 w中只有一个数  那么说明当前w中这个数 不满足某约束  则将其加入RT中 打印输出
               if(s.size()==0 && w.size()==1){
                   RT.add(w.get(0));
                   PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub);
                   //sum_time += time;
                   break car;
               }
           }else if(w.size()==1){
               RT.add(w.get(0));
               PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub);
               //sum_time += time;
               break car;
           }else if(w.size()==0){
               break car;
           }
            sdrone:
            for (j = 0; j < s.size(); j++) {
                RU.add(s.get(j));//加完之后  直接把无人机的载重给拉满  这样每次就只能访问一个节点
                w.remove(s.get(j));
                f.add(s.get(j));
                double Ud = Distance.sumUd(RU);
                int Uzz = Capcity.Uzz(RU);

                int rucount = RU.size();
                //******************************************************************************距离判断分支 2
                if (Ud >= D && rucount == 2) {

                    Integer ru_last = RU.get(RU.size() - 1);
                    Integer rt_last = RT.get(RT.size() - 1);
                    w.add(ru_last);
                    f.remove(ru_last);
                    RU.clear();
                    RU.add(RT.get(RT.size() - 1));
                    Integer w_closest = Distance.wDistance1(rt_last, w);
                    RT.add(w_closest);
                    l = GAData.disCollection[rt_last][w_closest];
                    w.remove(w_closest);
                    f.add(w_closest);
                    int f_demand = Capcity.fD(f);//已访问节点中 的需求

                    if (f_demand < Q) {
                        if (w.size() > 0) {
                            s = Distance.sProduce(w, RU);//重新根据RU的最后一个点 生成 新的S
                            if(s.size()==0 && w.size()==1){//这个判断比较关键   决定的是 所剩下的 未访问节点 均无法再被无人机访问的情况
                                RT.add(w.get(0));
                                PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub);
                                //sum_time += time;
                                break car;
                            }
                            j = -1;//从0 开始 遍历新的s
                            continue sdrone;
                        } else {
                            PrintRoute.printRoute_w0(RT, RU,w, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            break car;
                        }
                    } else if (f_demand == Q) {//需要换辆车
                        if (w.size() > 0) {

                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        } else {
                            PrintRoute.printRoute_w0(RT, RU,w, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            break car;
                        }
                    } else if (f_demand > Q) {
                        RT.remove(RT.get(RT.size() - 1));
                        w.add(RT.get(RT.size() - 1));
                        f.remove(RT.get(RT.size() - 1));
                        PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;

                        continue car;
                    }
                    //**********************************************************************距离判断分支 1
                } else if (Ud == D && rucount > 2) {
                    RT.add(RU.get(RU.size() - 1));  //将RU内最后一个点加入RT
                    drone_trip = DroneTripUpdate.Method(hub, RU); //将当前RU存在 drone trip里
                    //来吧  更新这个地方 应该是保存完 无人机路径后  给车安排  给车安排到 车辆载重满了  然后直接 换车
                    for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                            Integer rt_last = RT.get(RT.size()-1);
                            Integer rt_add = Distance.wDistance1(rt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                        RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                        if(w.size()>0){
                            if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                continue;
                            }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }else{// 加了一个发现刚好把 w中的点给加完了
                            if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                break car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }
                    }
                    RU.clear();
                    //寻找未访问节点集w中距离RT内最后一个点 距离最近的两个点，并加入RT 纠正错误：应该是最近的一个点  与 当前这个最近点 最近的点
                    if (w.size() > 1) {
                        Integer the_closest = Distance.wDistance1(RT.get(RT.size() - 1), w);
                        RT.add(the_closest);w.remove(the_closest);
                        Integer the_second = Distance.wDistance1(the_closest, w);
                        RT.add(the_second);w.remove(the_second);
                        //将RU内的节点清除掉   并将上述theclosest点 加入RU内 作为新的起飞点
                        RU.add(the_closest);
                        f.add(the_closest);
                        f.add(the_second);
                        l = GAData.disCollection[the_closest][the_second];
                        //下列为 一模一样的步骤
                        int f_demand = Capcity.fD(f);//已访问节点中 的需求
                        if (f_demand < Q) {
                            if (w.size() > 0) {
                                s = Distance.sProduce(w, RU);
                                j = -1;
                                continue sdrone;
                            } else {//加了两个点到RT   但是满足总体载重需求  所以直接打印就好
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                //sum_time += time;
                                if(RT.size()==1){
                                    Integer kkk=1;
                                }
                                break car;
                            }

                        } else if (f_demand == Q) { //加了点后  刚好达到载重要求   打印出当前的路径 换车
                           PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(RT.size()==1){
                                int k =0;
                            }
                            continue car;
                        } else {
                            RT.remove(the_closest);
                            RT.remove(the_second);
                            w.add(the_closest);
                            w.add(the_second);
                            f.add(the_closest);
                            f.add(the_second);
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        }
                    } else if (w.size() == 0) {  //如果 所有节点正好全部访问完
                        PrintRoute.printRoute_w0(RT, RU, w,drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        if(RT.size()==1){
                            Integer kkk=1;
                        }
                        break car;// 跳出大循环
                    } else if (w.size() == 1) {
                        PrintRoute.printRoute_w1(RT, RU, w, drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        break car;
                    }
                    //********************************************************距离判断分支3
                } else if (Ud > D && rucount > 3) {//
                    RT.add(RU.get(RU.size() - 2));//将RU中倒数第二个点加入RT
                    w.add(RU.get(RU.size() - 1));
                    f.remove(RU.get(RU.size() - 1));//f 与 w 一增一减
                    RU.remove(RU.size() - 1);
                    drone_trip = DroneTripUpdate.Method(hub, RU);
                    for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                        Integer rt_last = RT.get(RT.size()-1);
                        Integer rt_add = Distance.wDistance1(rt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                        RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                        if(w.size()>0){
                            if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                continue;
                            }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }else{// 加了一个发现刚好把 w中的点给加完了
                            if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                break car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }
                    }
                    RU.clear();// 保存完 RU后  将 RU清空
                    //********************************************************************
                    if (w.size() > 1) {

                        Integer the_closest = Distance.wDistance1(RT.get(RT.size() - 1), w);
                        RT.add(the_closest);w.remove(the_closest);
                        Integer the_second = Distance.wDistance1(the_closest, w);
                        RT.add(the_second);w.remove(the_second);

                        RU.add(the_closest);//为下一个架次 设置起飞点
                        f.add(the_closest);
                        f.add(the_second);
                        l = GAData.disCollection[the_closest][the_second];
                        int f_demand = Capcity.fD(f);//已访问节点中 的需求

                        if (f_demand < Q) {
                            if (w.size() > 0) {
                                s = Distance.sProduce(w, RU);
                                j = -1;
                                continue sdrone;
                            } else {//加了两个点到RT   但是满足总体载重需求  所以直接打印就好
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                //sum_time += time;
                                continue car;
                            }

                        } else if (f_demand == Q) { //加了点后  刚好达到载重要求   打印出当前的路径 换车
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        } else {
                            RT.remove(the_closest);
                            RT.remove(the_second);
                            w.add(the_closest);
                            w.add(the_second);
                            f.add(the_closest);
                            f.add(the_second);
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        }
                    } else if (w.size() == 0) {  //如果 所有节点正好全部访问完
                        PrintRoute.printRoute(RT, RU,  drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        break car;// 跳出大循环
                    } else if (w.size() == 1) {
                       PrintRoute.printRoute_w1(RT, RU, w, drone_trip,obj,truck_hub,drone_hub);
                        break car;
                    }
                } else if (Ud > D && rucount == 3) {
                    Integer ru_last = RU.get(RU.size() - 1);
                    Integer ru_second = RU.get(RU.size() - 2);
                    RU.clear();
                    w.add(ru_last);
                    w.add(ru_second);
                    f.remove(ru_last);
                    f.remove(ru_second);
                    Integer rt_last = RT.get(RT.size() - 1);
                    RU.add(rt_last);//将rt内最后一个点设为ru中的新的起飞点
                    Integer w_closest = Distance.wDistance1(rt_last, w);
                    RT.add(w_closest);
                    l = GAData.disCollection[rt_last][w_closest];
                    w.remove(w_closest);
                    f.add(w_closest);

                    int f_demand = Capcity.fD(f);//已访问节点中 的需求
                    if (f_demand < Q) {
                        if (w.size() > 0) {
                            s = Distance.sProduce(w, RU);
                            j = -1;//从0 开始 遍历新的s
                            continue sdrone;
                        } else {
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            break car;
                        }
                    } else if (f_demand == Q) {
                        if (w.size() > 0) {
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        } else {
                            PrintRoute.printRoute_w0(RT, RU, w,drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            break car;
                        }
                    } else if (f_demand > Q) {
                        RT.remove(RT.get(RT.size() - 1));
                        w.add(RT.get(RT.size() - 1));
                        f.remove(RT.get(RT.size() - 1));
                        PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                        continue car;
                    }

                } else if (Ud < D && Uzz == M && rucount > 2) {
                    //************************************************************载重判断分支1
                    RT.add(RU.get(RU.size() - 1));  //将RU内最后一个点加入RT
                    drone_trip = DroneTripUpdate.Method(hub, RU); //将当前RU存在 drone trip里
                    for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                        Integer rt_last = RT.get(RT.size()-1);
                        Integer rt_add = Distance.wDistance1(rt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                        RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                        if(w.size()>0){
                            if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                continue;
                            }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }else{// 加了一个发现刚好把 w中的点给加完了
                            if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                break car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }
                    }
                    RU.clear();
                    //寻找未访问节点集w中距离RT内最后一个点 距离最近的两个点，并加入RT
                    if (w.size() > 1) {
                        Integer the_closest = Distance.wDistance1(RT.get(RT.size() - 1), w);
                        RT.add(the_closest);w.remove(the_closest);
                        Integer the_second = Distance.wDistance1(the_closest, w);
                        RT.add(the_second);w.remove(the_second);
                        //将RU内的节点清除掉   并将上述theclosest点 加入RU内 作为新的起飞点
                        RU.add(the_closest);
                        //更新w 与 f   更新 l
                        f.add(the_closest);
                        f.add(the_second);
                        l = GAData.disCollection[the_closest][the_second];
                        //下列为 一模一样的步骤
                        int f_demand = Capcity.fD(f);//已访问节点中 的需求
                        if (f_demand < Q) {
                            if (w.size() > 0) {
                                s = Distance.sProduce(w, RU);
                                j = -1;
                                continue sdrone;
                            } else {
                                PrintRoute.printRoute(RT, RU, drone_trip, obj, truck_hub, drone_hub);
                            }
                        } else if (f_demand == Q) {
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        } else {
                            RT.remove(the_closest);
                            RT.remove(the_second);
                            w.add(the_closest);
                            w.add(the_second);
                            f.add(the_closest);
                            f.add(the_second);
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            continue car;
                        }
                        if(w.size()==0){
                            break car;
                        }
                        w.add(RT.get(RT.size() - 1));
                        f.remove(RT.get(RT.size() - 1));
                        RT.remove(RT.size() - 1);
                        PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        continue car;
                    } else if (w.size() == 0) {  //如果 所有节点正好全部访问完
                        PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        break car;// 跳出大循环
                    } else if (w.size() == 1) {
                        PrintRoute.printRoute_w1(RT, RU, w, drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        break car;
                    }
                } else if (Ud < D && Uzz > M && rucount > 2) {
                    //*********************************************************载重判断分支3
                    RT.add(RU.get(RU.size() - 1));//将RU中倒数第一个点加入RT
                    drone_trip = DroneTripUpdate.Method(hub, RU);
                    for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                        Integer rt_last = RT.get(RT.size()-1);
                        Integer rt_add = Distance.wDistance1(rt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                        RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                        if(w.size()>0){
                            if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                continue;
                            }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }else{// 加了一个发现刚好把 w中的点给加完了
                            if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                break car;
                            }else{ //大于  把最后加的那个 吐出来
                                w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                continue car;
                            }
                        }
                    }
                    RU.clear();// 保存完 RU后  将 RU清空
                    //********************************************************************
                    if (w.size() > 1) {

                        Integer the_closest = Distance.wDistance1(RT.get(RT.size() - 1), w);
                        RT.add(the_closest);w.remove(the_closest);
                        Integer the_second = Distance.wDistance1(the_closest, w);
                        RT.add(the_second);w.remove(the_second);

                        RU.add(the_closest);//为下一个架次 设置起飞点
                        f.add(the_closest);
                        f.add(the_second);
                        l =GAData.disCollection[the_closest][the_second];

                        int f_demand = Capcity.fD(f);//已访问节点中 的需求

                        if (f_demand < Q) {
                            if (w.size() > 0) {
                                s = Distance.sProduce(w, RU);
                                j = -1;
                                continue sdrone;
                            } else {//加了两个点到RT   但是满足总体载重需求  所以直接打印就好
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                //sum_time += time;
                                break car;
                            }

                        } else if (f_demand == Q) { //加了点后  刚好达到载重要求   打印出当前的路径 换车
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            continue car;
                        } else {
                            RT.remove(the_closest);
                            RT.remove(the_second);
                            w.add(the_closest);
                            w.add(the_second);
                            f.add(the_closest);
                            f.add(the_second);
                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            if(w.size()==1){
                                int k = 0;
                            }
                            continue car;
                        }
                    } else if (w.size() == 0) {  //如果 所有节点正好全部访问完
                        PrintRoute.printRoute(RT, RU,  drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        break car;// 跳出大循环
                    } else if (w.size() == 1) {
                        PrintRoute.printRoute_w1(RT, RU, w, drone_trip,obj,truck_hub,drone_hub);
                        //sum_time += time;
                        break car;
                    }

                    }else if(Ud<D && Uzz>=M && rucount==2) {//如果无人机路径里 只有两个点但是 载重已经超负荷
                    RT.add(RU.get(1));//把这个点 送给 车
                    RU.remove(1);//从无人机中移除
                    if(w.size()>0){
                        s = Distance.sProduce(w, RU);//重新生成 s
                        j=-1;
                        continue sdrone;//重新为无人机寻找 客户点
                    }else{
                        PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub);
                        break car;
                    }

                }else if (Ud < D && Uzz < M && Ud >= 1.5 * l) {
                        //*****************************************************1.5l判断 分支 1
                        if (w.size() > 0) {  // 如果未访问的节点数目大于1
                            Integer rt_last = RT.get(RT.size() - 1);
                            Integer rt_last_closest = Distance.wDistance1(rt_last, w);
                            RT.add(rt_last_closest);
                            w.remove(rt_last_closest);
                            f.add(rt_last_closest);
                            l += GAData.disCollection[rt_last][rt_last_closest];//当前RU内起飞点为起点
                            //下列为 一模一样的步骤

                            int f_demand = Capcity.fD(f);//已访问节点中 的需求
                            if (f_demand < Q) {
                                if (w.size() > 0) {
                                    s = Distance.sProduce(w, RU);
                                    j = -1;//从0 开始 遍历新的s
                                    continue sdrone;
                                } else { //w.size == 0
                                    if(RU.size()==1){
                                        PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub); //sum_time += time;
                                         break car;
                                    }else if(RU.size()==2){
                                        RU.add(RT.get(RT.size()-1));
                                        drone_trip = DroneTripUpdate.Method(hub, RU);
                                        for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                                            Integer rtt_last = RT.get(RT.size()-1);
                                            Integer rt_add = Distance.wDistance1(rtt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                                            RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                                            if(w.size()>0){
                                                if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                                    continue;
                                                }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    continue car;
                                                }else{ //大于  把最后加的那个 吐出来
                                                    w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    continue car;
                                                }
                                            }else{// 加了一个发现刚好把 w中的点给加完了
                                                if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    break car;
                                                }else{ //大于  把最后加的那个 吐出来
                                                    w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    continue car;
                                                }
                                            }
                                        }
                                        PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub);
                                        //sum_time += time;
                                        break car;
                                    }else if(RU.size()>=3){
                                        RT.add(RU.get(RU.size()-1));//将RU内最后一个节点作为降落点
                                        drone_trip = DroneTripUpdate.Method(hub, RU);//
                                        for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                                            Integer rtt_last = RT.get(RT.size()-1);
                                            Integer rt_add = Distance.wDistance1(rtt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                                            RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                                            if(w.size()>0){
                                                if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                                    continue;
                                                }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    continue car;
                                                }else{ //大于  把最后加的那个 吐出来
                                                    w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    continue car;
                                                }
                                            }else{// 加了一个发现刚好把 w中的点给加完了
                                                if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    break car;
                                                }else{ //大于  把最后加的那个 吐出来
                                                    w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                                    continue car;
                                                }
                                            }
                                        }
                                        PrintRoute.printRoute(RT,RU,drone_trip,obj,truck_hub,drone_hub);
                                        break car;
                                    }
                                }
                            } else if (f_demand == Q) {
                                if (w.size() > 0) {
                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                    //sum_time += time;
                                    continue car;
                                } else {
                                    PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                    //sum_time += time;
                                    break car;
                                }
                            } else if (f_demand > Q) {
                                Integer rt__last = RT. get(RT.size() - 1);
                                RT.remove(rt__last);
                                w.add(rt__last);
                                f.remove(rt__last);
                                RU.add(RT.get(RT.size()-1));
                                drone_trip = DroneTripUpdate.Method(hub, RU);
                                for(int ol = 0;ol<w.size();ol++){// 这个for循环是为了 在找到一个无人机架时  把车辆的访问点给填满
                                    Integer rtt_last = RT.get(RT.size()-1);
                                    Integer rt_add = Distance.wDistance1(rtt_last,w); //这里就是求 w中 距离RT内最后一个点最近的点
                                    RT.add(rt_add); w.remove(rt_add);f.add(rt_add);

                                    if(w.size()>0){
                                        if(Capcity.fD(f)<GAData.capacityTruck){  //小于
                                            continue;
                                        }else if(Capcity.fD(f)==GAData.capacityTruck){ //等于
                                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                            continue car;
                                        }else{ //大于  把最后加的那个 吐出来
                                            w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                            continue car;
                                        }
                                    }else{// 加了一个发现刚好把 w中的点给加完了
                                        if(Capcity.fD(f)<=GAData.capacityTruck){  //小于
                                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                            break car;
                                        }else{ //大于  把最后加的那个 吐出来
                                            w.add(rt_add);RT.remove(rt_add);f.remove(rt_add);
                                            PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                            continue car;
                                        }
                                    }
                                }
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub);
                                //sum_time += time;

                                continue car;
                            }
                        } else if (w.size() == 0) {  //如果 所有节点正好全部访问完
                            PrintRoute.printRoute_w0(RT, RU, w, drone_trip,obj,truck_hub,drone_hub);
                            //sum_time += time;
                            break car;// 跳出大循环
                        }
                    } else if (Ud < D && Uzz < M && Ud < 1.5 * l) {//当选择s中数时  选完一个数需要判断w中节点数 、 f_demand与Q的关系
                        if (w.size() == 0) {
                            PrintRoute.printRoute_w0(RT, RU, w, drone_trip,obj,truck_hub,drone_hub);  //sum_time += time;
                             break car;
                        } else if (w.size() > 0) {
                            int f_demand = Capcity.fD(f);
                            if (f_demand < Q) {
                                continue sdrone;//当 w中仍有节点且 当前访问节点需求 小于 车辆载重  则继续
                            } else {
                                w.add(RU.get(RU.size() - 1));
                                f.remove(RU.get(RU.size() - 1));
                                RU.remove(RU.size() - 1);
                                PrintRoute.printRoute(RT, RU, drone_trip,obj,truck_hub,drone_hub); //sum_time += time;
                                continue car;
                            }
                        }

                    }
            }
        }
        obj[0] = truck_hub;obj[1] = drone_hub;
        return obj;
    }
    }
